package com.ywgt.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywgt.response.Result;
import com.ywgt.system.pojo.Log;
import com.ywgt.system.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 操作日志表 前端控制器
 * </p>
 *
 * @author yiping
 * @since 2021-01-22
 */
@RestController
@Api(value = "日志模块",tags = "日志模块")
@RequestMapping("/system/log")
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation(value = "查询日志",notes = "根据条件查询日志")
    @GetMapping("/findLogList")
    public Result findLogList(@RequestParam(value = "pageNum",defaultValue = "1",required = false)Long pageNum,
                              @RequestParam(value = "pageSize",defaultValue = "3",required = false)Long pageSize,
                              Log log){
       Page<Log> logPage= logService.findLogList(pageNum,pageSize,log);
        List<Log> pageRecords = logPage.getRecords();
        long total = logPage.getTotal();
        return Result.ok().data("rows",pageRecords).data("total",total);
    }

    @ApiOperation(value = "删除日志",notes = "根据id删除日志")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id")Long id){
        if (logService.removeById(id)){
            return Result.ok();
        }
        return Result.error();
    }

    @ApiOperation(value = "批量删除日志",notes = "批量删除日志")
    @DeleteMapping("/batchDelete/{ids}")
    public Result batchDelete(@PathVariable("ids")Long [] ids){
        List<Long> id = Arrays.asList(ids);
        if (logService.removeByIds(id)){
            return Result.ok();
        }
        return Result.error();
    }
}

